// 登录
function login() {
	return (let = `<form action="../html/index.html" id="register" class="tcenter plr20 boxs">
	<img src="../images/loginlogo.png" alt="" class="mt38b42">
	<p class="font20 cut">
		<span class="c00 activer rel">账号登录</span>
		<i></i>
		<span class="rel">扫码登录</span>
	</p>
	<div class="login">
		<p class="zhu mt30 tleft">
			<span></span>
			<input type="text" placeholder="用户名/手机号/邮箱" class="pl30 boxs" id='usename'>
			<i class = 'cred'>请输入用户名/手机号/邮箱</i>
		</p>
		<p class="zhu mt18 tleft">
			<span class="last"></span>
			<input type="text" placeholder="密码" class="pl30 boxs" id='psw'>
			<i class = 'cred'>请输入6至12位数字.字母.下划线的密码</i>
		</p>
		<p class="tright font14 c00 mt16b12">
			忘记密码
		</p>
		<p>
			<button>登录</button>
		</p>
		<p class="font14 mt18">
			还没有源码账号，<span class="c00 skip">立即注册</span>
			<a href="#">&gt;</a>
		</p>
	</div>
	<div class="scan mt43">
		<div class="dfbc fdc font14">
			<img src="../images/103-demo.png" alt="" height="100px">
			<p>微信扫码登录</p>
			<p>未关注源码科技公众号,请关注后再登录</p>
		</div>
		<p class="font14 mt18 tleft">
			还没有源码账号，<span class="c00 skip">立即注册</span>
			<a href="#">&gt;</a>
		</p>
	</div>
	<img src="../images/clearInput.png" alt="" width="20px">
</form>`);
}
//获取元素
/**
 * @deprecated 实现元素的获取
 * @param {string} selector选择器
 * @returns
 */
function $(selector) {
	let ss = document.querySelectorAll(selector);
	switch (ss.length) {
		case 1:
			return ss[0];
		case 0:
			return console.warn(`${selector}没有获取到节点`);
		default:
			return ss;
	}
}

/**
 *
 * @param {string} selector选择器
 * @param {Boolean}  false为多选择器,否则相反
 * @returns
 */
/* function $(selector, flsg = true) {
	let ss = flsg
		? document.querySelector(selector)
		: document.querySelectorAll(selector);
	return ss;
} */
/**
 * @deprecated 判断是否为移动端或者为电脑
 */
function phone() {
	const userAgent = navigator.userAgent;
	//验证是否为Andriod或iPhone
	const android = userAgent.match(/(Android);?[￥s￥/]+([￥d.]+)?/);
	const iphone = userAgent.match(/(iPhone￥sOS)￥s([￥d_]+)/);
	if (android || iphone) {
		location.href = "http://m.itcast.cn";
	}
}
//数组去重
/**
 * @deprecated 数组去重
 * @param {[]} arr 数组
 * @returns
 */
function deWeight(arr = []) {
	const arrs = [];
	arr.forEach(function (v) {
		if (!arrs.includes(v)) {
			arrs.push(v);
		}
	});
	return arrs;
}

const myjs = {
	//随机颜色
	/**
	 * @deprecated 获取任意随机颜色
	 * @param {Boolean} flag
	 * @returns
	 */
	getRandomColor(flag = true) {
		if (flag === true) {
			let color = [
				"0",
				"1",
				"2",
				"3",
				"4",
				"5",
				"6",
				"7",
				"8",
				"9",
				"a",
				"b",
				"c",
				"d",
				"e",
				"f",
			];
			let dd = `#`;
			let ss = 0;
			for (let i = 0; i < 6; i++) {
				ss = color[Math.floor(Math.random() * 16)];
				dd += ss;
			}
			return dd;
		} else {
			let r = Math.floor(Math.random() * 256);
			let g = Math.floor(Math.random() * 256);
			let b = Math.floor(Math.random() * 256);
			return `rgb(${r},${g},${b})`;
		}
	},
	//返回n-m的随机数
	/**
	 * @deprecated 获取两数之间的随机数
	 * @param {Number} m 小的数
	 * @param {Number} n 大的数
	 * @returns
	 */
	getRandom(m = 0, n = 0) {
		return Math.floor(Math.random() * (n - m + 1) + m);
	},
	//倒计时函数
	getTime(time1) {
		const time = new Date();
		// let time1 = new Date(2023, 2, 14, 12, 0, 0);
		let total = Math.round((time1.getTime() - time.getTime()) / 1000);
		let hours = Math.floor(total / (60 * 60));
		let minutes = Math.floor((total % (60 * 60)) / 60);
		let second = Math.floor(total % 60);
		p.innerHTML = `下课倒计时: ${fun(hours)} : ${fun(minutes)} : ${fun(
			second
		)}`;
	},
};

//本地存取
const local = {
	//得到
	/**
	 * @deprecated 从本地获取序列化的字符串并转化
	 * @param {*} key 键名
	 * @returns
	 */
	getItem(key) {
		return JSON.parse(localStorage.getItem(key));
	},
	/**
	 * @deprecated 把字符串序列化并存储到本地
	 * @param {*} key 键名
	 * @param {*} value 键值
	 * @returns
	 */
	//添加
	setItem(key, value) {
		localStorage.setItem(key, JSON.stringify(value));
	},
	/**
	 * @deprecated 删除本地名为key的键值对
	 * @param {*} key 键名
	 * @returns
	 */
	//删除
	removeItem(key) {
		localStorage.removeItem(key);
	},
	/**
	 * @deprecated 删除本地所有
	 * @returns
	 */
	//全部删除
	clear() {
		localStorage.clear();
	},
};
